<!--
 * @Description: 
 * @Date: 2020-12-21 17:36:24
 * @LastEditors: lother
 * @LastEditTime: 2021-01-05 17:33:51
 * @FilePath: \AccountOpening-H5\src\views\features\pact.vue
-->
<template>
    <div>
        <l-header :sliderShow="false" :closeShow="false" :title="title" :backShow="true"></l-header>
        <div>
            <div class="w89" v-if="is_pdf?true:false">
                <div v-html="content"></div>
            </div>
            <div v-if="!is_pdf?true:false" class="pdf">
                 <pdf  v-for="i in numPages" :key="i"  :src="pdf_url" :page="i"></pdf> 
            </div>
        </div>
    </div>
</template>
<script>
  import pdf from 'vue-pdf'
  import { agreementId } from '@/api/common' 
export default {
    name:"pact",
    components: {
        pdf
    },
    data() {
        return {
            content:"",
            pdf_url:"",
            is_pdf:true,
            numPages:1,
            title:""
        }
    },
    computed:{
       
        langSuff(){
            return  this.$store.state.langSuff
        },
    },
    mounted(){
        this.agreementId()
    },
    methods:{
        getNumPages(url) {
            var loadingTask = pdf.createLoadingTask(this.pdf_url)
            loadingTask.promise.then(pdf => {
                this.pdf_url = loadingTask
                this.numPages = pdf.numPages
            }).catch((err) => {
                console.error('pdf加载失败')
            })
      },
      agreementId(){
          agreementId(this.$route.params.id)
          .then(res=>{
              if(res.code==1){
                  this.title = res.data['name_'+this.langSuff]
                  this.is_pdf =  (res.data.is_pdf==1?true:false)
                  if(res.data.is_pdf==2){
                      this.pdf_url = res.data['pdf_url_'+this.langSuff]
                      this.getNumPages()
                  }else{
                      this.content = res.data['content_'+this.langSuff]
                  }
              }
          })
      }
    }
}
</script>
<style lang="less" scoped>
    .pdf{
        width:100%;
        position: relative;
        overflow: hidden;
        @{deep}img{
            max-width: 100%;
        }
    }
</style>